<template>
  <ma-crud ref="crudRef" :columns="columns" :options="crud">
    <template #search-packageName="{ searchForm, component }">
      <a-input
        v-model.trim="searchForm[component.dataIndex]"
        :style="{ width: '240px' }"
        allow-clear
        placeholder="请输入套餐名称"
      >
        <template #prefix>
          <icon-search />
        </template>
      </a-input>
    </template>
  </ma-crud>
</template>

<script lang="ts" name="TenantPackage" setup>
import { addTenantPackage, delTenantPackage, listTenantPackage, updateTenantPackage } from "@/api/system/tenantPackage";

const crud = reactive({
  id: "packageId",
  pk: "packageId",
  title: "套餐查询",
  formOption: {
    width: 600
  },
  api: listTenantPackage,
  showIndex: true,
  operationColumn: true,
  operationColumnAlign: "center",
  operationColumnWidth: 150,
  pageLayout: "normal",
  requestParams: { orderBy: "createTime", orderType: "desc" },
  add: { api: addTenantPackage, auth: ["system:tenantPackage:add"], text: "新增", show: true },
  delete: { api: delTenantPackage, auth: ["system:tenantPackage:delete"], text: "删除", show: true },
  edit: { api: updateTenantPackage, auth: ["system:tenantPackage:edit"], text: "编辑", show: true },
  beforeOpenEdit: (formData: any) => {
    formData.menuIds = formData.menuIdList;
    return true;
  }
});

const columns = reactive([
  {
    title: "套餐编号",
    dataIndex: "packageId",
    align: "center",
    hide: true
  },
  {
    title: "套餐名称",
    dataIndex: "packageName",
    align: "center",
    search: true,
    commonRules: [{ required: true, message: "套餐名称不能为空" }]
  },
  {
    title: "菜单权限",
    dataIndex: "menuIds",
    formType: "tree",
    align: "center",
    hide: true,
    fieldNames: {
      key: "id",
      title: "label",
      children: "children"
    },
    dict: {
      url: "/system/menu/treeSelect",
      method: "get",
      openPage: false,
      cache: false
    }
  },
  {
    title: "套餐状态",
    dataIndex: "status",
    align: "center",
    formType: "radio",
    dict: {
      name: "sys_normal_disable",
      cache: true,
      props: { label: "dictLabel", value: "dictValue" },
      translation: true,
      tagColors: true
    },
    addDefaultValue: 0
  },
  {
    title: "描述",
    dataIndex: "remark",
    align: "center",
    formType: "textarea",
    autoSize: { minRows: 3, maxRows: 6 },
    maxLength: 200
  }
]);
</script>
